import {ApiResponse, http as api, ListResponse, SearchKeyQueryParam} from 'slash-admin'
import {SysTbSecurityObjFieldResponse} from "@/views/AuthTbUser/UserBindDataSecurity/UserBindDataSecurityField.vue";


export interface SysTbSecurityObjResponse {
    id: string,
    createTime: string,
    updateTime: string,
    createUserAccount: string,
    updateUserAccount: string,
    securityObjName: string,
    securityObjEntityName: string,
    securityObjTableName: string,
    resourceAppCode: string,
}

export interface SelectSysTbSecurityObjPageListQueryParam extends SearchKeyQueryParam {

}

/**
 * 分页查询列表
 * @param query
 */
export const selectPageList = (query: SelectSysTbSecurityObjPageListQueryParam): Promise<ListResponse<SysTbSecurityObjResponse>> => {
    return api.doGet('/SysApp/SysTbSecurityObj/selectPageList', query)
}
/**
 * 根据ID查询
 * @param id
 */
export const selectById = (id: string | number): Promise<ApiResponse<SysTbSecurityObjResponse>> => {
    return api.doGet('/SysApp/SysTbSecurityObj/selectById', {id: id})
}


/**
 * 新增
 * @param data
 */
export const doSaveEntity = (data: any): Promise<ApiResponse<boolean>> => {
    return api.doPost('/SysApp/SysTbSecurityObj/save', data)
}
/**
 * 实体
 * @param data
 */
export const doUpdateEntity = (data: any): Promise<ApiResponse<boolean>> => {
    return api.doPost('/SysApp/SysTbSecurityObj/update', data)
}
/**
 * 逻辑删除
 * @param id|ids
 */
export const doLogicDeleteEntity = (ids: Array<string | number> | number | string): Promise<ApiResponse<boolean>> => {
    let data: any = null;
    if (Array.isArray(ids)) {
        data = ids;
    } else {
        data = [ids];
    }
    return api.doPost('/SysApp/SysTbSecurityObj/logicDelete', data)
}
/**
 * 物理删除
 * @param id|ids
 */
export const doDeleteEntity = (ids: Array<string> | number | string): Promise<ApiResponse<boolean>> => {
    let data: any = null;
    if (Array.isArray(ids)) {
        data = ids;
    } else {
        data = [ids];
    }
    return api.doPost('/SysApp/SysTbSecurityObj/delete', data)
}
/**
 * 分页查询列表
 * @param query
 */
export const selectTreeList = (query: SelectSysTbSecurityObjPageListQueryParam): Promise<ListResponse<SysTbSecurityObjResponse>> => {
    return api.doGet('/SysApp/SysTbSecurityObj/selectTreeList', query)
}
/**
 * 分页查询列表
 * @param query
 */
export const selectDataPermissions = (query: SelectSysTbSecurityObjPageListQueryParam): Promise<ListResponse<SysTbSecurityObjResponse>> => {
    let queryParams = '';
    let count = Object.keys(query)?.length || 0;
    Object.keys(query).forEach((key, index) => {
        queryParams += `${key}=${query[key]}${index<(count-1) ? '&' : ''}`;
    })
    return api.doPost(`/AuthApp/DataPermissions/selectDataPermissions?${queryParams}`)
}
export const batchUpdateUserDataSecurity = (data: any) => {
    return api.doPost('/AuthApp/AuthFkUserSecurityObjField/batchUpdate', data)
}
export const batchUserUpdate = (data: any) => {
    return api.doPost('/AuthApp/AuthFkUserSecurityObjField/batchUserUpdate', data)
}

/**
 * 分页查询列表
 * @param query
 */
export const selectSysTbSecurityObjFieldPageList = (query: any): Promise<ListResponse<SysTbSecurityObjFieldResponse>> => {
    return api.doGet('/SysApp/SysTbSecurityObjField/selectPageList', query)
}
/**
 * 分页查询列表
 * @param query
 */
export const selectByUserId = (query: any): Promise<ListResponse<SysTbSecurityObjFieldResponse>> => {
    return api.doGet('/AuthApp/AuthFkUserSecurityObjField/selectByUserId', query)
}
export default {
    selectByUserId,

    batchUpdateUserDataSecurity,
    selectDataPermissions,
    selectSysTbSecurityObjFieldPageList,
    selectTreeList,
    selectPageList,
    selectById,
    doDeleteEntity,
    doLogicDeleteEntity,
    doUpdateEntity,
    doSaveEntity,
    batchUserUpdate
}
